package cn.vcjf.weapp.api.goods.controller;


import org.springframework.web.bind.annotation.RequestMapping;
import javax.annotation.Resource;
import org.springframework.web.bind.annotation.ResponseBody;
import cn.vcjf.weapp.common.web.TableResult;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import cn.vcjf.weapp.api.goods.entity.GoodsBrand;
import cn.vcjf.weapp.api.goods.service.GoodsBrandService;

import org.springframework.stereotype.Controller;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zhengzihang
 * @since 2018-09-25
 */
@Controller
@RequestMapping("/goods/goodsBrand")
public class GoodsBrandController {
     @Resource
     private GoodsBrandService  goodsBrandService;

     @RequestMapping("/addGoodsBrand")
     @ResponseBody
     public TableResult addGoodsBrand(GoodsBrand goodsBrand){
         goodsBrand.preInsert();
         boolean b = goodsBrandService.insert(goodsBrand);
         return TableResult.Result(b);
     }

     @RequestMapping("/updateGoodsBrand")
     @ResponseBody
     public TableResult updateGoodsBrand(GoodsBrand goodsBrand){
         goodsBrand.preUpdate();
        boolean b = goodsBrandService.updateById(goodsBrand);
         return TableResult.Result(b);
     }

     @RequestMapping("/findGoodsBrandOne")
     @ResponseBody
     public TableResult findGoodsBrandOne(GoodsBrand goodsBrand){

        EntityWrapper<GoodsBrand> wrapper = new EntityWrapper<GoodsBrand>();

        if(goodsBrand.getId()!=null){
            wrapper.eq("id",goodsBrand.getId());
        }
        //Todo

        GoodsBrand result = goodsBrandService.selectOne(wrapper);

		return TableResult.OKResult(result);
     }

     @RequestMapping("/findGoodsBrandList")
     @ResponseBody
     public TableResult findGoodsBrandList(GoodsBrand goodsBrand){

        EntityWrapper<GoodsBrand> wrapper = new EntityWrapper<GoodsBrand>();

		if(goodsBrand.getId()!=null){
            wrapper.eq("id",goodsBrand.getId());
        }
        //Todo

        Page<GoodsBrand> page = goodsBrand.getPageInfo();

        page = goodsBrandService.selectPage(page,wrapper);

		return TableResult.OKResult(page);

     }

     @RequestMapping("/deleteGoodsBrand")
     @ResponseBody
     public TableResult deleteGoodsBrand(GoodsBrand goodsBrand){
        goodsBrand.preUpdate();
        boolean b = goodsBrandService.deleteById(goodsBrand.getId());
        return TableResult.Result(b);
     }

}
